<script>
    var colModel = [{
        name: 'goodsName',
        index: 'goodsName',
        width: 120,
        label: '名称',
        frozen: true,
        sortable: true,
        align: "center",
        classes: 'td-padding'
    }, {
        name: 'goodsSn',
        index: 'goodsSn',
        label: '货号',
        width: 120,
        align: "center",
        frozen: true,
        sortable: true
    }, {
        name: 'barCode',
        index: 'barCode',
        label: '条码',
        align: "center",
        width: 120,
        frozen: true
    }, {
        name: 'imagine',
        index: 'imagine',
        width: 80,
        align: "center",
        label: '图片',
        formatter: imgFormat
    }, {
        name: 'skuSn',
        index: 'skuSn',
        label: '单品编号',
        width: 120,
        hidden: true
    }, {
        name: 'colorId',
        index: 'colorId',
        width: 120,
        label: '颜色',
        align: "center",
        formatter: colorNamesDecode,
        unformat: colorNamesUndecode,
        sortable: true
    }, {
        name: 'sizeId',
        index: 'sizeId',
        width: 120,
        label: '尺码',
        align: "center",
        formatter: sizeNamesDecode,
        unformat: sizeNamesUndecode,
        sortable: true
    }, {
        name: 'sizeId',
        index: 'sizeId',
        width: 120,
        label: '尺码',
        hidden: true,
        frozen: true
    }, {
        name: 'blandId',
        index: 'blandId',
        label: '品牌',
        width: 80,
        align: "center",
        formatter: blandNamesDecode,
        sortable: true
    }, {
        name: 'categoryId',
        index: 'categoryId',
        label: '分类',
        align: "center",
        width: 80,
        formatter: categoryNamesDecode,
        sortable: true
    }, {
        name: 'storehouseId',
        index: 'storehouseId',
        align: 'center',
        hidden: true
    }, {
        name: 'factoryPrice',
        index: 'factoryPrice',
        label: '采购价',
        align: "center",
        width: 70,
        sortable: true,
        hidden: true
    }, {
        name: 'tradePrice',
        index: 'tradePrice',
        label: '吊牌价',
        align: "center",
        width: 70,
        sortable: true,
        hidden: true
    }, {
        name: 'retailPriceArea',
        index: 'retailPriceArea',
        label: '零售价',
        align: "center",
        width: 70,
        sortable: true,
        hidden: true
    }, {
        name: 'styleName',
        index: 'styleName',
        width: 120,
        align: 'center',
        label: '款式'
    }, {
        name: 'seasonName',
        index: 'seasonName',
        label: '季节',
        align: "center",
        width: 80
    }, {
        name: 'seasonId',
        index: 'seasonId',
        label: '季节ID',
        hidden: true
    }, {
        name: 'year',
        index: 'year',
        label: '年份',
        align: "center",
        width: 90
    }, {
        name: 'number',
        index: 'number',
        label: '当前库存数量',
        align: "center",
        width: 90,
        sortable: true
    }, {
        name: 'operate',
        index: 'operate',
        width: 80,
        formatter: operAdjust,
        label: '库存盘点',
        align: "center", fixed: true, resizable: false, sortable: false,
        hidden: true
    }, {
        name: 'goodsId',
        index: 'goodsId',
        hidden: true
    }];

    var colModelData = angular.copy(colModel);

    //显示列表主函数
    $(document).ready(function () {

        $("#list_section").jqGrid({
            cmTemplate: {sortable: false},
            jsonReader: {
                root: 'data',
                page: 'current_page',
                total: 'last_page',
                records: 'total'
            },
            prmNames: {
                search: "search"
            },
            datatype: 'local', // 得得到后台传入前台的方式到后台传入前台的方式
            /*sortable: true,*/
            multiSort: true,
            colModel: colModel, // --显示的列。
            pager: "#pager", // --得到分页的层
            rowNum: 20,
            // rowNum:${pager.pageSize} , //
            // --一页显示几行？
            page: 1, // --从弟几页开始
            rowlist: [10, 20, 30], // --多少页一段
            height: "100%",
            width: "100%",
            //postData: {existsNumber: 1},
            viewrecords: true,
            autowidth: true,
            shrinkToFit: false,
            gridComplete: afterCompleteFunction,
            beforeRequest: function () {
                $('.tb_operating').hide();
            },
            loadComplete: function () {
                $('.tb_operating').show();
                adjustFrozenColumnHeight('list_section');
                disableTarget(getScope("FormCtrl").target, false);
            },
            loadError: function () {
                disableTarget(getScope("FormCtrl").target, false);
            },
        });

        $("#list_section").jqGrid('navGrid', '#pager', {
            refresh: false,
            edit: false,
            add: false,
            del: false,
            search: false,
            addfunc: openDialog4Adding, // (1)
            editfunc: openDialog4Updating
        }, {
            closeOnEscape: true,
            closeAfterAdd: true,
            serializeEditData: function (data) {
                return $.param($.extend({}, data, {
                    id: ''
                }));
            }
        });

        //修复排序列表头样式
        var myGrid = $("#list_section");
        var cm = myGrid[0].p.colModel;
        $.each(myGrid[0].grid.headers, function (index, value) {
            var cmi = cm[index], colName = cmi.name;
            if (cmi.sortable && colName !== 'rn' && colName !== 'cb' && colName !== 'subgrid') {
                $('div.ui-jqgrid-sortable', value.el).addClass('sortable');
                $('div.ui-jqgrid-sortable', value.el).prepend('<span class="sortable-icon"></span>');
            }
        });

        //库存调整表单
        $("#adjustDialog").dialog({
            autoOpen: false,
            height: 480,
            width: 650,
            resizableType: false,
            modal: true,
            title: "库存盘点"
        });
        //库存调整表单end

        $(function () {
            $("#errorDialog").dialog({
                autoOpen: false,
                show: {
                    effect: "blind",
                    duration: 10
                },
                minWidth: 500,
                modal: true,
                title: "无法查询"
            });
        });

        //设置jqgrid表头对齐方式
        $("#list_section").jqGrid("setLabel", "goodsName", "", {"text-align": "center"});
        $("#list_section").jqGrid("setLabel", "goodsSn", "", {"text-align": "center"});
        $("#list_section").jqGrid("setLabel", "skuSn", "", {"text-align": "center"});
        $("#list_section").jqGrid("setLabel", "colorId", "", {"text-align": "center"});
        $("#list_section").jqGrid("setLabel", "sizeId", "", {"text-align": "center"});
        $("#list_section").jqGrid("setLabel", "blandId", "", {"text-align": "center"});
        $("#list_section").jqGrid("setLabel", "factoryPrice", "", {"text-align": "center"});
        $("#list_section").jqGrid("setLabel", "tradePrice", "", {"text-align": "center"});
        $("#list_section").jqGrid("setLabel", "retailPriceArea", "", {"text-align": "center"});
        $("#list_section").jqGrid("setLabel", "warnNumberTop", "", {"text-align": "center"});
        $("#list_section").jqGrid("setLabel", "warnNumberLow", "", {"text-align": "center"});
        $("#list_section").jqGrid("setLabel", "number", "", {"text-align": "center"});
        $("#list_section").jqGrid("setLabel", "number", "", "sortable-align-fix");
        $("#list_section").jqGrid("setLabel", "factoryPrice", "", "sortable-align-fix");
        $("#list_section").jqGrid("setLabel", "tradePrice", "", "sortable-align-fix");
        $("#list_section").jqGrid("setLabel", "retailPriceArea", "", "sortable-align-fix");

        //冻结列
        $("#list_section").jqGrid('setFrozenColumns');
        adjustFrozenDivHeight('list_section');

        for (var i = 0; i < getScope("FormCtrl").columnItemList.length; i++) {
            var item = getScope("FormCtrl").columnItemList[i].id;
            if (contains(getScope("FormCtrl").displayItem.columnItemList, item)) {
                $("#list_section").setGridParam().showCol(item);
            } else {
                $("#list_section").setGridParam().hideCol(item);
            }
        }

        function searchWarnLimitCount() {
            $("#list_section").setGridParam({datatype: 'json'});
            setTimeout(function () {
                var scope = getScope("FormCtrl");
                scope.$apply(function () {
                    scope.storehouse = {
                        val: 'merge',
                        text: '合并仓库统计'
                    };
                    scope.searchVO.storehouseId = 'merge';
                    // 商品列表
                    scope.displayItem.listModel = 1;
                    scope.searchVO.warnNumber = true;
                    scope.setWarnNumber();
                    scope.search();
                    scope.getSumData();
                });

            }, 50);
        }

        function searchNegativeCount() {
            $("#list_section").setGridParam({datatype: 'json'})
            setTimeout(function () {
                var scope = getScope("FormCtrl");
                scope.$apply(function () {
                    scope.storehouse = {
                        val: 'merge',
                        text: '合并仓库统计'
                    };
                    // 商品列表
                    scope.displayItem.listModel = 1;
                    scope.searchVO.storehouseId = 'merge';
                    add(scope.displayItem.searchItemList, 'number');
                    scope.searchVO.maxNumber = -1;
                    scope.search();
                    scope.getSumData();

                });

            }, 50);
        }

        if ($.getUrlParam("searchWarnLimitCount")) {
            eval($.getUrlParam("searchWarnLimitCount"));
        }
        if ($.getUrlParam("searchNegativeCount")) {
            eval($.getUrlParam("searchNegativeCount"));
        }
        if (!$.getUrlParam("searchWarnLimitCount") && !$.getUrlParam("searchNegativeCount")) {

            $("#list_section").setGridParam({datatype: 'json'});
            if (getScope("FormCtrl").displayItem.listModel == 1) {
                getScope("FormCtrl").changeToGoodsListModel();
            } else if (getScope("FormCtrl").displayItem.listModel == 2) {
                getScope("FormCtrl").changeToSkuListModel();
            }
        }

        if (!$("#size-cross").is(':checked')) {
            $("#sel-miss").css('display', 'none');
        }
    });

    function openDialog4Updating() {
    }

    function openDialog4Adding() {
    }


    //标红库存报警商品
    function afterCompleteFunction() {

        $("#list_section").setGridWidth($("#list_section").parent().parent().parent().parent().parent().width());
        var scopeCtrl = getScope('FormCtrl');
        if (scopeCtrl.searchVO.storehouseId != 'merge') {
            var rowDatas = $("#list_section").jqGrid('getRowData');

            for (var i = 0; i < rowDatas.length; i++) {
                var rowData = rowDatas[i];

                if (rowData['number'] != "") {
                    if ((rowData['warnNumberLow'] != "" && parseInt(rowData['number']) < parseInt(rowData['warnNumberLow']))
                        || (rowData['warnNumberTop'] != "" && parseInt(rowData['number']) > parseInt(rowData['warnNumberTop']))) {
                        $("#" + rowData.serialNo).find("td").css("color", "red");
                    }
                }
            }
        }

    }

    //打开库存调整窗口
    var storedAdjust = function (rowid) {
        var scopeCtrl = getScope('FormCtrl');
        //行数据
        var rowData = $('#list_section').jqGrid('getRowData', rowid);

        scopeCtrl.adjustVO = {};
        //清空校验状态
        scopeCtrl.adjustForm.$setPristine();

        scopeCtrl.$apply(function (scope) {
            scope.adjustVO = {
                goodsId: rowData['goodsId'],
                goodsSn: rowData['goodsSn'],
                goodsName: rowData['goodsName'],
                currentSku: rowData['skuSn'],
                colorId: parseInt(rowData['colorId']),
                colorName: colorNamesDecode(rowData['colorId']),
                sizeId: parseInt(rowData['sizeId']),
                sizeName: sizeNamesDecode(rowData['sizeId']),
                quantity: rowData['number'],
                number: 1
            };
        });

        $("#adjustDialog").dialog("open");
        $("#adjustNumber").focus();
    };

    /**
     * 库存调整列操作项格式化
     */
    function operAdjust(val, opt, row) {
        var html_con = "<span class='tb_operating'><span title='库存调整' class='ui-icon ui-icon-pencil' onclick='storedAdjust(" + "\"" + opt.rowId + "\"" + ")'></span></span>";
        return html_con;
    }

    //自适应宽度
    $(window).resize(function () {
        $("#list_section").setGridWidth($("#list_section").parent().parent().parent().parent().parent().width());
    })


    // angularjs模块定义
    var goodsApp = angular.module('JxApp', ["checklist-model", 'JxApp.mulsel', 'JxApp.levelsel', 'ipCookie']);

    goodsApp.controller("FormModule", function ($scope, $filter, $http, ipCookie) {

        $scope.isloadSizeCrossWise = false;
        $scope.sortArray = [];
        $scope.sizeWiseSord = "desc";

        // 查询统计数据
        $scope.getSumData = function (searchParam) {
            if (!$scope.showSumData) {
                return;
            }

            if (!searchParam) {
                searchParam = angular.copy($scope.searchParam);
            }

            $scope.sumDataLoading = true;
            $http.get('{{ route('admin.shop.stock.query.getGoodsStoredSumData') }}', {params: searchParam}).success(function (result) {
                $scope.sumData = result;
                $scope.sumDataLoading = false;
            });
        };

        $scope.initList = function () {
            $scope.sumDataLoading = false;
            $scope.showSumData = false;
            $scope.showSumDataStyle = {display: 'none'};
            $scope.allBland = allBland;
            $scope.allCategory = allCategory;
            $scope.categoryJson = allCategoryList;
            $scope.seasons = strSeasonListJson;
            $scope.allStyleJson = strStyleListJson;
            $scope.blands = allBland;
            $scope.allYears = allYears;
            $scope.allSizeJson = allSizes;
            $scope.allColorJson = allColors;

            $scope.jqgridUrl = '{{ route('admin.shop.stock.query.getGoodsStoredList') }}';
            /*列表查询设置初始化*/
            $scope.searchItemList = [
                {id: 'bland', name: '品牌'},
                {id: 'category', name: '分类'},
                {id: 'number', name: '当前库存数量'},
                {id: 'color', name: '颜色'},
                {id: 'size', name: '尺码'},
                {id: 'style', name: '款式'},
                {id: 'material', name: '材质'},
                {id: 'unit', name: '单位'},
                {id: 'year', name: '年份'},
                {id: 'season', name: '季节'},
                {id: 'existsNumber', name: '过滤无库存'},
                {id: 'zeroNumber', name: '过滤零库存'},
                {id: 'warnNumber', name: '库存预警'}
            ];
            $scope.columnItemList = [
                {id: 'imagine', name: '图片'},
                {id: 'blandId', name: '品牌'},
                {id: 'categoryId', name: '分类'},
                {id: 'colorId', name: '颜色'},
                {id: 'sizeId', name: '尺码'},
                {id: 'skuSn', name: '单品编号'},
                {id: 'styleName', name: '款式'},
                {id: 'seasonName', name: '季节'},
                {id: 'year', name: '年份'},
                {id: 'factoryPrice', name: '采购价'},
                {id: 'tradePrice', name: '吊牌价'},
                {id: 'retailPriceArea', name: '零售价'},
            ];

            $scope.displayItem = {
                listModel: 2, //列表模式：1-商品列表，2-单品列表
                searchItemList: ['goodsSn', 'category', 'bland', 'color', 'size', 'style', 'year', 'season', 'sumData'],//查询条件
                columnItemList: ['imagine', 'categoryId', 'colorId', 'sizeId', 'blandId', 'categoryId', 'factoryPrice', 'tradePrice', 'retailPriceArea', 'year', 'styleName', 'seasonName'] //列表字段
            };

            $scope.searchVO = {existsNumber: true,zeroNumber:1};
            $scope.getSumData();
        };

        $scope.initList();

        $scope.getShowSumDataText = function () {
            if ($scope.showSumData) {
                return '收起统计数据';
            } else {
                return '展示统计数据';
            }
        };

        $scope.changeShowSumData = function () {
            $scope.showSumData = !$scope.showSumData;
            if ($scope.showSumData) {
                $scope.showSumDataStyle = {display: 'block'};
            } else {
                $scope.showSumDataStyle = {display: 'none'};
            }

            $scope.getSumData();
        };

        // 查询按钮
        $scope.search = function () {
            var categoryIds = getChildIds(allCategoryList, $scope.searchVO.categoryId);

            var zeroNumber = 0;

            if($('#zeroNumber').is(':checked')) {
                zeroNumber = 1;
            }

            var searchParam = {
                goodsName: $scope.searchVO.searchKey,
                goodsSn: $scope.searchVO.searchKey,
                barCode: $scope.searchVO.searchKey,
                skuSn: $scope.searchVO.searchKey,
                blandId: $scope.searchVO.blandId,
                categoryId: categoryIds,
                colorId: $scope.search.colorIds,
                sizeId: $scope.search.sizeIds,
                styleId: $scope.search.styleId,
                year: $scope.search.year,
                seasonId: $scope.search.seasonId,
                zeroNumber:zeroNumber,
                operator: 3, //操作符,为3则对名称、货号、条码等取或
                // 1代表商品， 2代表单品
                listDataType: $scope.displayItem.listModel
            };

            //商品列表模式时，不可做库存调整
            if ($scope.displayItem.listModel == 1) {
                $("#list_section").setGridParam().hideCol("operate");
            } else if ($("#gbox_list_section").css("display") != "none") {
                $("#list_section").setGridParam().showCol("operate");
            }

            $("#list_section").setGridWidth($("#list_section").parent().parent().parent().parent().parent().width());
            //手动清空postdata
            $("#list_section").setGridParam({postData: null});
            $("#list_section").setGridParam({postData: {page: 1}});

            disableTarget($scope.target, false, true);
            $scope.target = getEvtTarget();
            disableTarget($scope.target, true);

            $("#list_section").jqGrid("setGridParam", {
                postData: searchParam,
                url: $scope.jqgridUrl // 传入后台的地址。
            }).trigger("reloadGrid", [{
                page: 1
            }]); // 重新载入Grid表格

            $scope.searchParam = searchParam;//保存最后一次查询结果对应的查询条件,以供用作获取统计数据的查询条件

            $scope.getSumData();
        };


        /**
         * 库存调整窗口取消按钮响应函数
         */
        $scope.cancleAdjust = function () {
            $("#adjustDialog").dialog("close");
        };

        /**
         * 库存调整窗口“调整”按钮响应函数
         *
         */
        $scope.directAdjust = function () {
            $scope.savingGoodsStoredSet = true;
            var remark = "库存单个商品盘点";
            if ($scope.adjustVO.remark != undefined) {
                remark = remark + ' ' + $scope.adjustVO.remark;
            }

            //盘点单类型orderType：1-调整单，2-盘点单
            var storeOrder = {orderType: 2, status: 1, remark: remark, scene:'single_take'};
            var goods = [];

            var beforeNumber = 0;
            if ($scope.adjustVO.quantity != '' || $scope.adjustVO.quantity != null) {
                beforeNumber = $scope.adjustVO.quantity;
            }

            goods.push({
                goods_id: $scope.adjustVO.goodsId,
                goods_no: $scope.adjustVO.goodsSn,
                goods_name: $scope.adjustVO.goodsName,
                currentSku: $scope.adjustVO.currentSku,
                color_id: $scope.adjustVO.colorId,
                color: $scope.adjustVO.colorName,
                size_id: $scope.adjustVO.sizeId,
                size: $scope.adjustVO.sizeName,
                quantity: $scope.adjustVO.number,
                beforeNumber: beforeNumber
            });

            //提交订单
            $http.post('{{ route('admin.shop.take.stock.store') }}', $.param({
                order: angular.toJson(storeOrder),
                goods: angular.toJson(goods)
            }), {
                headers:
                    {
                        'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
                    }
            }).success(function (result) {
                $scope.savingGoodsStoredSet = false;
                if (result.status) {
                    swal("保存成功", result.message, "success");
                    $scope.search();
                    $scope.getSumData();
                    $("#list_section").trigger("reloadGrid");
                    $("#adjustDialog").dialog("close");
                } else {
                    swal('保存失败', result.message, 'warning');
                }
            }).error(function (data, status) {
                $scope.savingGoodsStoredSet = false;
            });

        };

        /**
         * 导出
         */
        $scope.excelExport = function () {
            var postData = $("#list_section").jqGrid("getGridParam", "postData");
            if ($scope.printOrderType == '101') {
                // 导出商品库存信息
                window.open(base + '/admin/inner/excelImport/goodsStored/goodsStoredExport.ac?' + $.param(postData));
            } else if ($scope.printOrderType == '102') {
                // 导出单品库存信息
                window.open(base + '/admin/inner/excelImport/goodsStored/goodsSkuStoredExport.ac?' + $.param(postData));
            } else if ($scope.printOrderType == '103') {
                // 导出单品库存信息
                window.open(base + '/admin/inner/excelImport/goodsStored/goodsSizeCrossWiseExport.ac?' + $.param($scope.searchParam));
            }
        };

        $scope.closeErrorDialog = function () {
            $("#errorDialog").dialog("close");
        };

        $scope.refreshPrintTemplate = function () {
            refreshPrintTemplate($scope, $http, '/admin/system/printTemplate/printTemplateListJSON.ac?orderType=' + $scope.printOrderType);
        };

        $scope.selTemplate = function (templateId) {
            selTemplate($scope, $http, ipCookie, templateId, null, parseInt($scope.printOrderType), "/admin/inner/storehouse/goodsStoredPrint.ac");
        };


        /********************** 列表设置 **********************/
        $scope.isShowSearchItem = function (searchItemName) {
            return ($scope.displayItem.searchItemList.indexOf(searchItemName) != -1);
        };


        $scope.repairGroupHeaders = function () {
            if ($scope.allSizes && $scope.allSizes.length > 1) {
                for (var i = 0; i < $scope.allSizes.length - 1; i++) {
                    var groupHeaders = [];
                    for (var j = 0; j < $scope.allSizes[i].length; j++) {
                        groupHeaders.push({
                            startColumnName: $scope.allSizes[$scope.allSizes.length - 1][j].id.toString(),
                            numberOfColumns: 1,
                            titleText: $scope.allSizes[i][j].name.toString()
                        });
                    }
                }
            }
        };

        $scope.checkListModel = function () {
            $("#list_section").jqGrid("clearGridData");
            if ($scope.displayItem.listModel == 1) {
                $scope.changeToGoodsListModel();
            } else if ($scope.displayItem.listModel == 2) {
                $scope.changeToSkuListModel();
            }
        };

        $('#checkListModel_1').on('ifChecked', function () {
            $scope.displayItem.listModel = $(this).val();
            $scope.checkListModel();
        });

        $('#checkListModel_2').on('ifChecked', function () {
            $scope.displayItem.listModel = $(this).val();
            $scope.checkListModel();
        });

        $scope.setWarnNumber = function () {
            // 库存预警自动勾选上过滤无库存
            $scope.searchVO.existsNumber = true;
            if ($scope.searchVO.warnNumber) {
                //勾选列表设置上“列表字段”的库存预警勾选框
                add($scope.displayItem.columnItemList, 'warnNumberTop');
                add($scope.displayItem.columnItemList, 'warnNumberLow');

                $("#list_section").setGridParam().showCol('warnNumberTop');
                $("#list_section").setGridParam().showCol('warnNumberLow');
            } else {
                //不勾选列表设置上“列表字段”的库存预警勾选框
                remove($scope.displayItem.columnItemList, 'warnNumberTop');
                remove($scope.displayItem.columnItemList, 'warnNumberLow');

                $("#list_section").setGridParam().hideCol('warnNumberTop');
                $("#list_section").setGridParam().hideCol('warnNumberLow');
            }
        };

        $scope.changeToGoodsListModel = function () {
            $("#gbox_list_section").show();

            $scope.jqgridUrl = '{{ route('admin.shop.stock.query.getGoodsStoredList') }}';
            $scope.search();

            //不勾选列表设置上“列表字段”的SKU勾选框
            remove($scope.displayItem.columnItemList, 'skuSn');
            add($scope.displayItem.searchItemList, 'size');
            add($scope.displayItem.searchItemList, 'existsNumber');
            add($scope.columnItemList, {id: 'sizeId', name: '尺码'});
            add($scope.searchItemList, {id: 'size', name: '尺码'});
            add($scope.searchItemList, {id: 'year', name: '年份'});
            add($scope.searchItemList, {id: 'styleName', name: '款式'});
            add($scope.searchItemList, {id: 'seasonName', name: '季节'});
            //不勾选列表设置上“列表字段”的颜色尺码勾选框

            //隐藏列表SKU列
            $("#list_section").setGridParam().hideCol('skuSn');

            //隐藏列表颜色尺码

            $("#list_section").setGridParam().showCol('year');
            $("#list_section").setGridParam().showCol('styleName');
            $("#list_section").setGridParam().showCol('seasonName');
        };

        $scope.changeToSkuListModel = function () {
            $scope.existsNumber = 1;
            $("#gbox_list_section").show();

            $scope.jqgridUrl = '{{ route('admin.shop.stock.query.getGoodsSkuStoredList') }}';
            $scope.search();

            remove($scope.displayItem.columnItemList, 'year');
            remove($scope.displayItem.columnItemList, 'styleName');
            remove($scope.displayItem.columnItemList, 'seasonName');
            //添加列表设置上“列表字段”的SKU勾选框
            add($scope.columnItemList, {id: 'skuSn', name: '单品编号'});
            add($scope.columnItemList, {id: 'sizeId', name: '尺码'});
            //勾选列表设置上“列表字段”的SKU勾选框
            add($scope.displayItem.columnItemList, 'skuSn');
            add($scope.displayItem.searchItemList, 'size');
            add($scope.displayItem.searchItemList, 'existsNumber');
            add($scope.searchItemList, {id: 'size', name: '尺码'});
            //勾选列表设置上“列表字段”的颜色尺码勾选框

            $("#list_section").setGridParam().showCol('skuSn');

            $("#list_section").setGridParam().hideCol('year');
            $("#list_section").setGridParam().hideCol('styleName');
            $("#list_section").setGridParam().hideCol('seasonName');
        };

        $scope.changeToSizeCrossWise = function (postData) {

            if ($scope.searchVO.existsNumber) {
                existsNumber = 1;
            } else {
                $scope.isExistsNumberFun();
            }

            if (!postData.page) {
                postData.page = 1;
            }
            postData.sord = $scope.sizeWiseSord;
            $("#gbox_list_section").hide();

            $http.post(base + '/admin/inner/storehouse/getGoodsSizeCrossWiseListJSON.ac', $.param(postData), {
                headers: {
                    'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
                }
            }).success(function (result) {
                $scope.allSizes = result.extData;
                var colModel = angular.copy(colModelData);
                if (!$scope.allSizes && !result.rows) {
                    $("#errorDialog").dialog("open");
                    return;
                }
                if ($scope.allSizes && $scope.allSizes.length > 0) {
                    var lastSizeGroup = $scope.allSizes[$scope.allSizes.length - 1];
                    for (var i = 0; i < lastSizeGroup.length; i++) {
                        var tempSize = {
                            index: lastSizeGroup[i].id.toString(),
                            name: lastSizeGroup[i].id.toString(),
                            label: lastSizeGroup[i].name,
                            width: 90,
                            align: "center"
                        }
                        colModel.splice(7 + i, 0, tempSize);
                    }
                }


                $scope.sizeWiseSort = "";
                for (var i = 0; i < $scope.sortArray.length; i++) {
                    $("#jqgh_list2_" + $scope.sortArray[i].index + " span.s-ico").show();
                    if ($scope.sortArray[i].sortorder == "asc") {
                        $("#jqgh_list2_" + $scope.sortArray[i].index + " span[sort='asc']").removeClass("ui-state-disabled");
                        $("#jqgh_list2_" + $scope.sortArray[i].index + " span[sort='desc']").addClass("ui-state-disabled");
                    } else if ($scope.sortArray[i].sortorder == "desc") {
                        $("#jqgh_list2_" + $scope.sortArray[i].index + " span[sort='asc']").addClass("ui-state-disabled");
                        $("#jqgh_list2_" + $scope.sortArray[i].index + " span[sort='desc']").removeClass("ui-state-disabled");
                    }
                }
                var reader = {
                    id: "serialNo",
                    root: function (obj) {
                        return result.rows;
                    },
                    page: function (obj) {
                        return result.page;
                    },
                    total: function (obj) {
                        return result.total;
                    },
                    records: function (obj) {
                        return result.records;
                    },
                    repeatitems: false
                };

                remove($scope.displayItem.columnItemList, 'skuSn');

                remove($scope.columnItemList, {id: 'sizeId', name: '尺码'});
                remove($scope.searchItemList, {id: 'size', name: '尺码'});
//			    remove($scope.displayItem.searchItemList, 'existsNumber');
                remove($scope.displayItem.searchItemList, 'size');


                $scope.repairGroupHeaders();
                $scope.isloadSizeCrossWise = true;
            })
        };
        /********************** 列表设置 end **********************/

        /*********************图片滑动相册****************************************/
        $scope.direction = 'left';
        $scope.currentIndex = 0;

        $scope.setCurrentSlideIndex = function (index) {
            $scope.direction = (index > $scope.currentIndex) ? 'left' : 'right';
            $scope.currentIndex = index;
        };

        $scope.isCurrentSlideIndex = function (index) {
            return $scope.currentIndex === index;
        };

        $scope.prevSlide = function () {
            $scope.direction = 'left';
            $scope.currentIndex = ($scope.currentIndex < $scope.slides.length - 1) ? ++$scope.currentIndex : 0;
        };

        $scope.nextSlide = function () {
            $scope.direction = 'right';
            $scope.currentIndex = ($scope.currentIndex > 0) ? --$scope.currentIndex : $scope.slides.length - 1;
        };
    });

    var getChildIds = function (list, startPid) {
        var ids = startPid;

        if (startPid != undefined && startPid != '') {
            if (list != undefined && list.length > 0) {
                for (var i = 0; i < list.length; i++) {
                    if (list[i]['pid'] == startPid) {
                        ids = ids + ',' + getChildIds(list, list[i]['id']);
                    }
                }

                return ids;
            } else {
                return startPid;
            }
        } else {
            return '';
        }

    };

    /* 商品缩略图 */
    function imgFormat(cellvalue, options, rowdata) {
        if (cellvalue) {
            return '<div class="img-gridlist" style="text-align:center; width:50px;height:50px;" onclick="openGallery(' + options.rowId + ');" ><img src="' + getListPictureUrl(cellvalue) + '" onload="imgLoaded()"></div>';
        } else {
            return '';
        }

    }

    function imgLoaded() {
        var that = this.event.target;
        var frozenTdHeight = parseFloat($(' #list_section_frozen' + ' #' + $(that).parents('tr').attr('id')).height());
        var normalHeight = parseFloat($(that).parents('tr').height());

        if (frozenTdHeight != normalHeight) {
            $(' #list_section_frozen' + ' #' + $(that).parents('tr').attr('id')).css('height', normalHeight);
        }
    }

    /**
     * 颜色ID串转为颜色名称串
     */
    function colorNamesDecode(cellvalue, options, rowdata) {
        if (cellvalue) {
            cellvalue = eval("\'" + cellvalue + "\'");
            var ids = cellvalue.split(',');
            var nameTemp;
            var nameList = [];
            var allColor = getScope('FormCtrl').allColorJson;
            for (var i = 0; i < ids.length; i++) {
                nameTemp = getObject(allColor, 'id', parseInt(ids[i]));
                if (nameTemp) {
                    nameList.push(nameTemp);
                }
            }
            nameList.sort(function (a, b) {
                if (a['showOrder'] > b['showOrder']) {
                    return 1;
                }
                if (a['showOrder'] < b['showOrder']) {
                    return -1;
                }
                if (a['id'] > b['id']) {
                    return 1;
                }
                if (a['id'] < b['id']) {
                    return -1;
                }
                return 0;
            });

            return nameList.map(function (elem) {
                return elem.name;
            }).join();
        } else {
            return '';
        }
    }

    /**
     * 颜色名称串转为颜色ID串
     */
    function colorNamesUndecode(cellvalue, options, rowdata) {
        if (cellvalue) {
            cellvalue = eval("\'" + cellvalue + "\'");
            var names = cellvalue.split(',');
            var idTemp = '';
            var ids = '';
            var allColor = getScope('FormCtrl').allColorJson;
            for (var i = 0; i < names.length; i++) {
                idTemp = getObject(allColor, 'name', names[i]);
                if (idTemp) {
                    ids = ids + ',' + idTemp.id;
                }
            }
            if (ids) {
                ids = ids.substr(1);
            } else {
                ids = '';
            }
            return ids;
        } else {
            return '';
        }
    }

    /**
     * 尺码ID串转为尺码名称串
     */
    function sizeNamesDecode(cellvalue, options, rowdata) {
        if (cellvalue) {
            cellvalue = eval("\'" + cellvalue + "\'");
            var ids = cellvalue.split(',');
            var nameTemp;
            var nameList = [];
            var allSize = getScope('FormCtrl').allSizeJson;
            for (var i = 0; i < ids.length; i++) {
                nameTemp = getObject(allSize, 'id', parseInt(ids[i]));
                if (nameTemp) {
                    nameList.push(nameTemp);
                }
            }
            nameList.sort(function (a, b) {
                if (a['showOrder'] > b['showOrder']) {
                    return 1;
                }
                if (a['showOrder'] < b['showOrder']) {
                    return -1;
                }
                if (a['id'] > b['id']) {
                    return 1;
                }
                if (a['id'] < b['id']) {
                    return -1;
                }
                return 0;
            });

            return nameList.map(function (elem) {
                return elem.name;
            }).join();
        } else {
            return '';
        }
    }

    /**
     * 尺码名称串转为尺码ID串
     */
    function sizeNamesUndecode(cellvalue, options, rowdata) {
        if (cellvalue) {
            cellvalue = eval("\'" + cellvalue + "\'");
            var names = cellvalue.split(',');
            var idTemp = '';
            var ids = '';
            var allSize = getScope('FormCtrl').allSizeJson;
            for (var i = 0; i < names.length; i++) {
                idTemp = getObject(allSize, 'name', names[i]);
                if (idTemp) {
                    ids = ids + ',' + idTemp.id;
                }
            }
            if (ids) {
                ids = ids.substr(1);
            } else {
                ids = '';
            }
            return ids;
        } else {
            return '';
        }
    }

    /**
     * 品牌ID转为品牌名称
     */
    function blandNamesDecode(cellvalue, options, rowdata) {
        if (cellvalue) {

            var nameTemp = getObject(allBland, 'id', cellvalue);

            if (nameTemp) {
                return nameTemp.name;
            } else {
                return '';
            }

        } else {
            return '';
        }
    }

    /**
     * 分类ID转为分类名称
     */
    function categoryNamesDecode(cellvalue, options, rowdata) {
        if (cellvalue) {

            var nameTemp = getObject(allCategoryList, 'id', cellvalue);

            if (nameTemp) {
                return nameTemp.name;
            } else {
                return '';
            }

        } else {
            return '';
        }
    }

    /**
     * 显示“是”或者“否” 1-是 2-否
     */
    function yearFromater(cellvalue, options, rowdata) {
        if (!cellvalue) {
            return '';
        } else if (parseFloat(cellvalue) - parseInt(cellvalue) == 0.5) {
            return cellvalue == '' ? '' : (parseInt(cellvalue) + '下');
        } else {
            return cellvalue == '' ? '' : (parseInt(cellvalue) + '上');
        }
    }

    /*回车事件*/
    $('#searchForm').keypress(function (e) {
        if (e.keyCode == '13') {
            stopEvent(e);
            $('#searchBtn').click();
        }
    });

    //初始化打印模板选择窗口
    $("#printTemplateListDiv").dialog({
        autoOpen: false,
        show: {
            effect: "blind",
            duration: 10
        },
        position: ['middle', 150],
        minWidth: 800,
        modal: true,
        title: "选择模板"
    });

    /*修复Jqgrid冻结列高度函数*/
    function adjustFrozenDivHeight(listId) {
        var bdivTop = -1;

        if (navigator.userAgent.toLowerCase().match(/opera/)) {
            divTop = 0;
            bdivTop = 0;
        }

        $('#gview_' + listId + ' .frozen-bdiv').css({
            top: $('#gview_' + listId + ' .frozen-bdiv').position().top + bdivTop
        });
    }

    function adjustFrozenColumnHeight(listId) {
        $('#gview_' + listId + ' .frozen-bdiv').css({
            height: 'auto'
        });
        $('#' + listId + '_frozen tr').slice(1).each(function () {
            var frozenTdHeight = parseFloat($('td:first', this).height());
            var normalHeight = parseFloat($(' #' + listId + ' #' + $(this).attr('id')).find('td:first').height());

            // 如果冻结的列高度小于未冻结列的高度则hack之
            if (frozenTdHeight != normalHeight) {
                $('td', this).each(function () {

                    /*浏览器差异高度hack*/
                    var space = 0; // opera默认使用0就可以
                    if (navigator.userAgent.toLowerCase().match(/chrome/)) {
                        space = 0.6;
                    } else if (navigator.userAgent.toLowerCase().match(/msie/)) {
                        space = 0.1;
                    } else if (navigator.userAgent.toLowerCase().match(/mozilla/)) {
                        space = 0.3;
                    }
                    $(this).css('height', normalHeight + space);
                });
            }

            //给图片绑定纠正tr高度方法
            $('#list_section img').each(function () {
                $(this).on("onload", function () {
                    var frozenTr = $(this).parent().parent().parent();
                    var normalTr = $("#list_section_frozen tr[id=" + frozenTr.attr('id') + "]");
                    if (frozenTr.height() != normalTr.height()) {
                        frozenTr.css('height', normalTr.height());
                    }
                });
            });
        });
    }

    //对于本地图片获取列表缩略图50*50
    var getListPictureUrl = function (url) {
        if (url != undefined && url != '') {
            if (url.indexOf("qinsilk.com") != -1) {
                return url + "@!pclist";
            } else {
                return url;
            }
        } else {
            return url;
        }
    };

    /*打开滑动电子相册*/
    var openGallery = function (rowid) {
        return;
        var FormCtrlScope = getScope('FormCtrl');
        //行数据
        var rowData = $('#list_section').jqGrid('getRowData', rowid);
        FormCtrlScope.slides = [];

        FormCtrlScope.$apply(function (scope) {
            var imgList = rowData['imgList'].split(',');
            for (var i = 0; i < imgList.length; i++) {
                scope.slides.push({url: imgList[i]});
            }
        });

        $("#slideGallery").dialog("open");
    };
    /*关闭滑动电子相册*/
    var closeGallery = function () {
        $("#slideGallery").dialog("close");
    };

    $("#slideGallery").dialog({
        autoOpen: false,
        show: {
            effect: "blind",
            duration: 10
        },
        position: ['middle', 100],
        width: 754,
        height: 504,
        modal: true,
        resizable: false,
        open: function () {
        },
        dialogClass: "slideGallery"
    });
</script>